<fieldset class="layui-elem-field layui-field-title">
	<legend>添加用户</legend>
</fieldset>



<form class="layui-form">

	<div class="layui-form-item">
		<label class="layui-form-label">姓名</label>
		<div class="layui-input-inline">
			<input type="text" name="name" placeholder="输入姓名" required lay-verify="required"
			  class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">身份证号</label>
		<div class="layui-input-inline">
			<input type="text" name="idcard" placeholder="输入身份证号" 
			required lay-verify="required"
				class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">电话号码</label>
		<div class="layui-input-inline">
			<input type="text" name="phone" placeholder="输入电话号码"
			required lay-verify="required"
				class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit lay-filter="user-add">立即提交</button>
		</div>
	</div>

</form>






<script>
layui.use(['form'],function(){
	var form = layui.form;
	form.on('submit(user-add)',function(data){
		$.ajax({
			url: '/api/user/add',
			data: data.field,
			type: 'post',
			dataType: 'json',
			success: function(result){
				if(result.code>0){   //>1?
				  layer.confirm('添加成功,继续添加还是查看？？', {btn:['继续','查看']}  ,function(index){
					  layer.close(index);
				  },
				  function(index){
					  layer.close(index);
					  open('/user/list.html');
				  }
				  );
				}else{
					layer.msg(result.msg);
				}
			},
			error: function(){
				layer.msg('请求失败');
			}
		});
		return false;
	});
});


</script>










































